<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.10"/>
<title>dev: dev/dev/net/Reactor.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">dev
   &#160;<span id="projectnumber">0.2</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.10 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('_reactor_8hpp_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Reactor.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/******************************************************************************</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * Name         : Reactor.hpp</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> * Author       : 671643387</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * Date         : 2015年9月6日</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * Description  : 网络事件派发器，检查事件源，派发事件</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> *****************************************************************************/</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#ifndef NET_REACTOR_HPP_</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#define NET_REACTOR_HPP_</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &lt;boost/noncopyable.hpp&gt;</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#include &lt;boost/smart_ptr/shared_ptr.hpp&gt;</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#include &lt;dev/net/Socket.hpp&gt;</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor">#include &lt;dev/net/SocketEventHandler.hpp&gt;</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacedev.html">dev</a></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;{</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;    <span class="keyword">namespace </span>net</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;    {</div>
<div class="line"><a name="l00023"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_reactor.html">   23</a></span>&#160;        <span class="keyword">class </span><a class="code" href="classdev_1_1net_1_1_reactor.html">Reactor</a> : <span class="keyword">public</span> boost::noncopyable</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;        {</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;        <span class="keyword">public</span>:</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;            <span class="keyword">enum</span> EventType</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;            {</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;                NONE,                   <span class="comment">// </span></div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;                READ = 0x1,             <span class="comment">// 读</span></div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;                WRITE = 0x2,            <span class="comment">// 写</span></div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;                EXCEP = 0x4,            <span class="comment">// 异常</span></div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;                RDWR = READ | WRITE,    <span class="comment">// 读/写</span></div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;                RDEX = READ | EXCEP,    <span class="comment">// 读/异常</span></div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;                WREX = WRITE | EXCEP,   <span class="comment">// 写/异常</span></div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;                ALL = RDWR | EXCEP      <span class="comment">// 读/写/异常</span></div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;            };</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;            <span class="keyword">enum</span> Status</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;            {</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;                READY,      <span class="comment">// 准备就绪</span></div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;                RUNNING,    <span class="comment">// 执行中</span></div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;                EXIT        <span class="comment">// 已退出</span></div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;            };</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        <span class="keyword">public</span>:</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;            <a class="code" href="classdev_1_1net_1_1_reactor.html">Reactor</a>() :status_(READY), heartBeatTime_(60000) {}</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;            <span class="keyword">virtual</span> ~<a class="code" href="classdev_1_1net_1_1_reactor.html">Reactor</a>(){}</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;        <span class="keyword">public</span>:</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;            <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_reactor.html#a53939a07465e8c772b63fb8d31a313ec">addSocket</a>(<a class="code" href="classdev_1_1net_1_1_socket.html">Socket</a>* sock, EventType events, <a class="code" href="classdev_1_1net_1_1_socket_event_handler.html">SocketEventHandler</a>* handler) = 0;</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;            <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_reactor.html#a032df9cb5073c0bbc387e8206c6a8507">removeSocket</a>(<a class="code" href="classdev_1_1net_1_1_socket.html">Socket</a>* sock) = 0;</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;            <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classdev_1_1net_1_1_reactor.html#a82d3315e9f4a00eff67ea868ab7e0b6b">tick</a>(<span class="keywordtype">int</span> timeout = 0) = 0;</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;            <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classdev_1_1net_1_1_reactor.html#a69c9596ef5f394df5824f753e7358685">clean</a>(<span class="keywordtype">void</span>) = 0;</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;        <span class="keyword">public</span>:</div>
<div class="line"><a name="l00079"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_reactor.html#a5e00626edea76a086d1db104345ee4ad">   79</a></span>&#160;            Status <a class="code" href="classdev_1_1net_1_1_reactor.html#a5e00626edea76a086d1db104345ee4ad">getStatus</a>(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> status_; }</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;</div>
<div class="line"><a name="l00085"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_reactor.html#a9ddff658f29b6d51a9f06c96a8176766">   85</a></span>&#160;            <span class="keywordtype">void</span> <a class="code" href="classdev_1_1net_1_1_reactor.html#a9ddff658f29b6d51a9f06c96a8176766">setStatus</a>(Status status) { status_ = status; }</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;</div>
<div class="line"><a name="l00091"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_reactor.html#a95cff3841403c0c59990a1969e6e62fa">   91</a></span>&#160;            <span class="keywordtype">int</span> <a class="code" href="classdev_1_1net_1_1_reactor.html#a95cff3841403c0c59990a1969e6e62fa">getHeartBeatTime</a>(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> heartBeatTime_; }</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;</div>
<div class="line"><a name="l00097"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_reactor.html#aba6f59dcdb9f1d73f11e022ef6af502b">   97</a></span>&#160;            <span class="keywordtype">void</span> <a class="code" href="classdev_1_1net_1_1_reactor.html#aba6f59dcdb9f1d73f11e022ef6af502b">setHeartBeatTime</a>(<span class="keywordtype">int</span> time) { heartBeatTime_ = time; }</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;        <span class="keyword">protected</span>:</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;            Status status_;     <span class="comment">// 状态</span></div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;            <span class="keywordtype">int</span> heartBeatTime_; <span class="comment">// 心跳间隔(毫秒)，默认60秒</span></div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;        };</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;        <span class="keyword">typedef</span> boost::shared_ptr&lt;Reactor&gt;   ReactorPtr;</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;    }</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;}</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;<span class="preprocessor">#endif </span><span class="comment">/* NET_REACTOR_HPP_ */</span><span class="preprocessor"></span></div>
<div class="ttc" id="namespacedev_html"><div class="ttname"><a href="namespacedev.html">dev</a></div><div class="ttdef"><b>Definition:</b> Atomic.hpp:18</div></div>
<div class="ttc" id="classdev_1_1net_1_1_reactor_html"><div class="ttname"><a href="classdev_1_1net_1_1_reactor.html">dev::net::Reactor</a></div><div class="ttdoc">网络反应器 </div><div class="ttdef"><b>Definition:</b> Reactor.hpp:23</div></div>
<div class="ttc" id="classdev_1_1net_1_1_reactor_html_a82d3315e9f4a00eff67ea868ab7e0b6b"><div class="ttname"><a href="classdev_1_1net_1_1_reactor.html#a82d3315e9f4a00eff67ea868ab7e0b6b">dev::net::Reactor::tick</a></div><div class="ttdeci">virtual void tick(int timeout=0)=0</div><div class="ttdoc">执行一次网络事件 </div></div>
<div class="ttc" id="classdev_1_1net_1_1_reactor_html_a69c9596ef5f394df5824f753e7358685"><div class="ttname"><a href="classdev_1_1net_1_1_reactor.html#a69c9596ef5f394df5824f753e7358685">dev::net::Reactor::clean</a></div><div class="ttdeci">virtual void clean(void)=0</div><div class="ttdoc">清理反应器 </div></div>
<div class="ttc" id="classdev_1_1net_1_1_reactor_html_a53939a07465e8c772b63fb8d31a313ec"><div class="ttname"><a href="classdev_1_1net_1_1_reactor.html#a53939a07465e8c772b63fb8d31a313ec">dev::net::Reactor::addSocket</a></div><div class="ttdeci">virtual bool addSocket(Socket *sock, EventType events, SocketEventHandler *handler)=0</div><div class="ttdoc">添加一个套接字到反应器 </div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_event_handler_html"><div class="ttname"><a href="classdev_1_1net_1_1_socket_event_handler.html">dev::net::SocketEventHandler</a></div><div class="ttdoc">套接字事件处理器 </div><div class="ttdef"><b>Definition:</b> SocketEventHandler.hpp:21</div></div>
<div class="ttc" id="classdev_1_1net_1_1_reactor_html_a032df9cb5073c0bbc387e8206c6a8507"><div class="ttname"><a href="classdev_1_1net_1_1_reactor.html#a032df9cb5073c0bbc387e8206c6a8507">dev::net::Reactor::removeSocket</a></div><div class="ttdeci">virtual bool removeSocket(Socket *sock)=0</div><div class="ttdoc">移除套接字 </div></div>
<div class="ttc" id="classdev_1_1net_1_1_reactor_html_a9ddff658f29b6d51a9f06c96a8176766"><div class="ttname"><a href="classdev_1_1net_1_1_reactor.html#a9ddff658f29b6d51a9f06c96a8176766">dev::net::Reactor::setStatus</a></div><div class="ttdeci">void setStatus(Status status)</div><div class="ttdoc">设置反应器状态 </div><div class="ttdef"><b>Definition:</b> Reactor.hpp:85</div></div>
<div class="ttc" id="classdev_1_1net_1_1_reactor_html_aba6f59dcdb9f1d73f11e022ef6af502b"><div class="ttname"><a href="classdev_1_1net_1_1_reactor.html#aba6f59dcdb9f1d73f11e022ef6af502b">dev::net::Reactor::setHeartBeatTime</a></div><div class="ttdeci">void setHeartBeatTime(int time)</div><div class="ttdoc">设置反应器心跳时间 </div><div class="ttdef"><b>Definition:</b> Reactor.hpp:97</div></div>
<div class="ttc" id="classdev_1_1net_1_1_reactor_html_a95cff3841403c0c59990a1969e6e62fa"><div class="ttname"><a href="classdev_1_1net_1_1_reactor.html#a95cff3841403c0c59990a1969e6e62fa">dev::net::Reactor::getHeartBeatTime</a></div><div class="ttdeci">int getHeartBeatTime(void) const </div><div class="ttdoc">获取反应器心跳时间 </div><div class="ttdef"><b>Definition:</b> Reactor.hpp:91</div></div>
<div class="ttc" id="classdev_1_1net_1_1_reactor_html_a5e00626edea76a086d1db104345ee4ad"><div class="ttname"><a href="classdev_1_1net_1_1_reactor.html#a5e00626edea76a086d1db104345ee4ad">dev::net::Reactor::getStatus</a></div><div class="ttdeci">Status getStatus(void) const </div><div class="ttdoc">获取反应器状态 </div><div class="ttdef"><b>Definition:</b> Reactor.hpp:79</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_html"><div class="ttname"><a href="classdev_1_1net_1_1_socket.html">dev::net::Socket</a></div><div class="ttdoc">套接字 </div><div class="ttdef"><b>Definition:</b> Socket.hpp:23</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_5fc0168d11760b9445bd29fa15d9290f.html">dev</a></li><li class="navelem"><a class="el" href="dir_1ca75188a6074d2843e8fd5d982c3101.html">dev</a></li><li class="navelem"><a class="el" href="dir_cea828ca1984caf90af75ecf8a99968a.html">net</a></li><li class="navelem"><b>Reactor.hpp</b></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.10 </li>
  </ul>
</div>
</body>
</html>
